<!DOCTYPE HTML>
<html>
<head>
<include file="Include:meta" />
<title>审核流程管理-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">审核流程管理</div>
	</div>
	<div id="content">
		<div class="filter">
			<div class="filter-item">
				<div class="filter-title">功能：</div>
				<ul class="filter-order">
					<foreach name="schedule_types" item="vo">
					<li <if condition="$type eq $vo['name2']">class="current"</if>>
						<a href="__APP__/System/audit_schedule_manage/type/{$vo['name2']}" tid="{$vo['id']}">{$vo['name1']}</a>
					</li>
					</foreach>
				</ul>
			</div>
		</div>
		<div class="table-scrollx">
			<table class="table table-bordered table-hover">
				<foreach name="audit_process" item="vo" key="k">
					<if condition="$k eq 0">
					<tr class="table-header fixed-table-header">
						<td rowspan="2" width="15%" class="middle Text_c">所属中心</td>
						<td colspan="{$audit_process_count}" class="Text_c">
							审核流程
						</td>
					</tr>
					<tr class="table-header fixed-table-header">
					</if>
						<td class="Text_c">{$vo['audit_name']}</td>
				</foreach>
				</tr>
				<foreach name="center_types" item="vo">
					<if condition="$vo['process'] neq NULL">
					<tr>
						<td class="nowrap">{$vo['first_name']}</td>
						<foreach name="vo['process']" item="wo">
							<td>
								<if condition="$wo['audit_user'] eq NULL"><span class="red">系统跳过</span>
								<else/><span class="users-list">{$wo['audit_user']}</span>
								</if>
								<a href="javascript:;" mid="{$wo['id']}" data-toggle="tooltip" data-placement="left" title="修改人员" class="selectuser-btn ml10"><i class="glyphicon glyphicon-edit"></i></a>
								<if condition="($wo['audit_user'] neq NULL) and ($type neq 1) and ($type neq 3) and ($type neq 5) and ($type neq 6) and ($type neq 7)">
									<a href="javascript:;" mid="{$wo['id']}" action="delete" data-toggle="tooltip" data-placement="right" title="删除人员" class="clear ml5"><i class="glyphicon glyphicon-trash"></i></a>
								</if>
							</td>
						</foreach>
					</tr>
					</if>
				</foreach>
			</table>
		</div>
	</div>
</div>
<!--选择人员-->
<div class="modal fade" id="selectuser-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>选择人员</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<foreach name="user_list" item="do">
					<div class="department">
						<label><input class="department-checkbox" type="checkbox" autocomplete="off" />{$do['name']}</label>
					</div>
					<ul>
						<foreach name="do['user']" item="uo">
							<li>
								<label><input class="user-checkbox" type="checkbox" value="{$uo['id']}" autocomplete="off" />{$uo['username']}</label>
							</li>
						</foreach>
					</ul>
				</foreach>
				<div class="modal-footer">
					<button type="button" class="btn user-affirm">确认</button><button type="button" class="btn btn-default user-cancel" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<include file="Include:javascript" />
<script type="text/javascript">
	$(function(){
		//删除人员
		$(".clear").ajaxModal({"title_text":"确认提示框","body_text":"您确定要删除吗？","url":"__APP__/Index/library_ajax","data":{"id":"zid","action":"action"}});
	});
	
	//选择用户
	(function(){
		var _this = "",
			$usermodal = $("#selectuser-modal"),
			$userbody = $usermodal.find(".modal-body");
			
		$(".selectuser-btn").click(function(){
			_this = $(this);
			$("#selectuser-modal").modal("show");
		});			
		
		//遍历选中用户
		$usermodal.on("show.bs.modal",function(){
			$usermodal.show();
			
			var $checkeduser = _this.parents("td").find(".users-list").text();
			
			$(this).find(":checkbox").prop("checked",false);
			$(this).find(".error-prompt").remove();
			if($checkeduser!=""){
				$checkeduser = $checkeduser.split(",");
				$(this).find(".user-checkbox").each(function(){
					var $user = $(this).parent("label").text();
					
					for(var i=0;i<$checkeduser.length;i++){
						if($user==$checkeduser[i]){
							$(this).prop("checked",true);
						}
					}
				});
			}
		});

		$usermodal.on("shown.bs.modal",function(){
			$(this).scrollTop(0);
		});

		//部门全选
		$usermodal.find(".department-checkbox").on("click",function(){
			var $ul = $(this).parents(".department").next("ul");

			if($(this).prop("checked")){
				$ul.find(".user-checkbox").prop("checked",true);
			}else{
				$ul.find(".user-checkbox").prop("checked",false);
				$usermodal.find(".all-checkbox").prop("checked",false);
			}
		});

		//用户单选
		$usermodal.find(".user-checkbox").on("click",function(){
			if(!$(this).prop("checked")){
				$(this).parents("ul").prev(".department").find(".department-checkbox").prop("checked",false);
				$usermodal.find(".all-checkbox").prop("checked",false);
			}
		});

		//确定选择用户
		$usermodal.find(".user-affirm").on("click",function(){
			var $usersub = false;

			$usermodal.find(".user-checkbox").each(function(){
				if($(this).prop("checked")){
					$usersub = true;
					return false;
				}
			});

			if($usersub){
				var $users = "",
					$uids = "",
					$mid = _this.attr("mid");

				$usermodal.find(".user-checkbox").each(function(){
					if($(this).prop("checked")){
						$users += $(this).parent("label").text()+",";
						$uids += $(this).val()+",";
					}
				}); 
				$users = $users.replace(/\,$/,"");
				$uids = $uids.replace(/\,$/,"");
				$usermodal.hide();
				$.ajax({
					type:"post",
					async:false,
					dataType:"json",
					data:{"action":"edit_user","mid":$mid,"user":$users,"uid":$uids},
					url:"__APP__/System/audit_schedule_manage_ajax",
					success:function(data){
						success_pop(data.status,data.msg);
					}
				});
			}else{
				$userbody.scrollTop(0);
				if($usermodal.find(".error-prompt").length==0){
					$usermodal.find(".modal-header").prepend("<span class='error-prompt'>至少选择一位人员</span>");
				}
			}
		});

		//取消错误提示
		$usermodal.find(":checkbox").on("click",function(){
			$usermodal.find(".error-prompt").remove();
		});
	})();
</script>
</html>